import i18n from "../i18n/index"
// 表单数据

// 注册账号表单数据格式
export class RouleForm {
    phoneNum: string = "" // 手机号
    verificationCode: string = "" // 验证码
    password1: string = "" // 密码
    password2: string = "" // 确认密码
}

// 注册表单校验配置
export const RouleFormData = {
    phoneNum: [
        { required: true, message: i18n.global.t("register_form_register_phoneRule1"), trigger: 'blur' },
        { pattern: /^1[3-9]\d{9}$/, message: i18n.global.t("register_form_register_phoneRule2"), trigger: 'blur' }
    ],
    verificationCode: [
        { required: true, message: i18n.global.t("register_form_register_verificationCodeRule1"), trigger: 'blur' }
    ],
    password1: [
        { required: true, message: i18n.global.t("register_form_register_password1Rule1"), trigger: 'blur' },
        {
            validator: (rule:any, value: any, callback: any) => {
                if (value === "") {
                    callback()
                } else if (value.trim().length < 6 || value.trim().length > 16) {
                    callback(i18n.global.t("register_form_register_password1Rule2"))
                }else {
                    callback()
                }
            }
        }
    ],
    password2: [
        { required: true, message: i18n.global.t("register_form_register_password2Rule1"), trigger: 'blur' },
        {
            validator: (rule: any, value: any, callback: any) => {
                const password1 = localStorage.getItem("password1")
                if (value == "") {
                    callback()
                } else if (password1 !== value) {
                    callback(new Error(i18n.global.t("register_form_register_password2Rule2")))
                } else {
                    callback()
                }
            }, trigger: 'blur'
        }
    ]
}

// 倒计时信息
export const countdownData = {
    second: 60,
    buttonName: i18n.global.t("register_form_register_verificationCode_btn"),
    isDisabled: false,
}

